package com.gt.controller.admin;


import com.gt.pojo.PageResult;
import com.gt.pojo.Result;
import com.gt.pojo.dto.NoticeDTO;
import com.gt.pojo.dto.NoticePageQueryDTO;
import com.gt.pojo.vo.NoticeVO;
import com.gt.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("admin/notice")
@RestController(value = "adminNoticeController")
@Api(tags = "公告管理模块")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;
    @PostMapping
    @ApiOperation("新增公告")
    public Result add(@RequestBody NoticeDTO noticeDTO){
        noticeService.add(noticeDTO);
        return Result.success();
    }
    @GetMapping("/page")
    @ApiOperation("公告分页查询")
    public Result<PageResult>page( NoticePageQueryDTO noticePageQueryDTO){
        PageResult pageResult = noticeService.pageQuery(noticePageQueryDTO);
        return Result.success(pageResult);
    }
    @DeleteMapping("/deleteBatch")
    @ApiOperation("批量删除公告")
    public Result delete(@RequestParam List<Long> ids){
        noticeService.deleteBatch(ids);
        return Result.success();
    }
    @DeleteMapping
    @ApiOperation("删除公告")
    public Result deleteById(Long id){
        noticeService.deleteById(id);
        return Result.success();
    }


    @ApiOperation("根据id查询公告")
    @GetMapping("/{id}")
    public Result<NoticeVO> getById(@PathVariable Long id){
        NoticeVO noticeVO = noticeService.getById(id);
        return Result.success(noticeVO);
    }

    @ApiOperation("修改公告")
    @PutMapping
    public Result update(@RequestBody NoticeDTO noticeDTO){
        noticeService.update(noticeDTO);
        return Result.success();
    }
}
